package pt.inescid.components.policyengine.heimdall.pip;

import java.util.Vector;

import pt.inescid.components.policyengine.heimdall.pap.base.DomainDefinition;

public class DomainManager {
	
	public static final int POLICY_SERVER = 1;
	public static final int STORAGE_NODES = 2;
	
	private static Vector allNodes = null;
	private static Vector policyServer = null;
	private static Vector localhost = null;

	/* ===========================================================
	==============================================================
	=============                    =============================
	=============      init()       =============================
	=============                    =============================
	==============================================================
	=========================================================== */
	public static void init() {

			allNodes = new Vector();
			allNodes.add(new NodeInfo("argentina.gsd.inesc-id.pt", 8001));
			allNodes.add(new NodeInfo("argentina.gsd.inesc-id.pt", 8002));

			policyServer = new Vector();
			policyServer.add(new NodeInfo("argentina.gsd.inesc-id.pt", 8002));

			localhost = new Vector();
			localhost.add(new NodeInfo("argentina.gsd.inesc-id.pt", 8001));
	}

	/* ===========================================================
	==============================================================
	=============                    =============================
	=============      getNodes       =============================
	=============                    =============================
	==============================================================
	=========================================================== */
	public static Vector getNodes(DomainDefinition currentDomain) {
//		if (allNodes == null) {
			init();
//		}
		
		if (currentDomain.getName().equals("allNodes")) {
			return (allNodes);
		}
		else if (currentDomain.getName().equals("policyServer")) {
			return (policyServer);
		}
		else if (currentDomain.getName().equals("localhost")) {
			return (localhost);
		}

		return (null);
	}

	/* ===========================================================
	==============================================================
	=============                    =============================
	=============      getNodeDomains (inverse)       =============================
	=============                    =============================
	==============================================================
	=========================================================== */
	public static Vector getNodeDomains(String node) {
		Vector allDomains = new Vector();
		
		if (node.contains("win")) {
			allDomains.add("allNodes");
			allDomains.add("localhost");
		}
		else if (node.contains("linux")) {
			allDomains.add("allNodes");
			allDomains.add("policyServer");
		}
		else if (node.contains("other")) {
			allDomains.add("allNodes");
		}

		return (allDomains);
	}


	
}; // DomainManager
